$(function(){
      $(".header-left").on("click",function(){
            history.back(-1);  
        });
    var productId =SYS_GLOBAL_CONFIG.getQueryString("productId");
    var url=SYS_GLOBAL_CONFIG.reqUrl,
        async="true",
        type="post";
    var data;
    console.log(url);
    
    var flag_collect=0;//设置初始值，判断服务是否收藏
    var user_id;
    var userId;
    if(window.localStorage){
        user_id=localStorage.userId;
    }else{
        user_id=getQueryString("userId");
        alert("请打开浏览器cookie功能,或者更换浏览器");
        console.log("当前浏览器不支持本地localStorage");
    }
    console.log(user_id);
    if(user_id!=undefined && user_id!="" && user_id!=null){
        userId=parseInt(user_id);
    }
    data=JSON.stringify({"code":"getServiceDetail","version":"1.0","data":{"productId":productId,"userId":userId}});
    console.log(data);               
    getData(url,data,call_func_succ,call_func_err,async,type);      
    
    /**
     *获取页面数据
     */
    function getData(url,requestData,call_func_succ,call_func_err,async,type){
            $.ajax({
                url:url,

                type:type,

                datatype:"json",

                contentType:"application/json",

                data:requestData,
                
                async:async,

                success:function(data){
                    call_func_succ(data);
                },
                error:function(msg){
                    call_func_err(msg);
                }   
            });        
        }
    /**
     *获取数据之后的回调函数
     */
   function call_func_succ(data){
       console.log(data);
       
        if(data.data){
            var isCollect=data.data.serviceInfo.isCollect;//服务是否收藏的标志
            var dataServiceInfo=data.data.serviceInfo;
           $(".head-pic").attr("src",dataServiceInfo.userImgPath)
           $(".span-name").html(dataServiceInfo.userName);
           console.log(dataServiceInfo.userAuthStatus+"这个服务");
           if(dataServiceInfo.userAuthStatus==1){//认证标志
                $(".image-tag").attr("src","./images/personService.png");
           }else{
                 $(".image-tag").get(0).style.display="none";
           }

           $(".hot-span1").html(dataServiceInfo.viewCount);
           $(".hot-span2").html(dataServiceInfo.serviceCollectCount);
           $(".p1").html(dataServiceInfo.productName);
            var str =dataServiceInfo.address;   
            if( str.split(" ").length>0){
                strs = str.split(" ");   
                $(".p2").html(strs[2]+"/"+strs[3]);
            }
           $(".p3").html(dataServiceInfo.parentServiceName +"&nbsp; . &nbsp;"+ dataServiceInfo.saleprice+"/"+dataServiceInfo.unit);
           $(".p4").html(dataServiceInfo.remark);
            
           $(".foot-span .message").attr("href","sms:"+dataServiceInfo.phoneNO);
           $(".foot-span .tell").attr("href","tel:"+dataServiceInfo.phoneNO);
            var len=dataServiceInfo.serviceImgs.length;
            var imgsData="";
            var lastIndex=0;
            var datafullpath="";
            if(len>0){
                for(var i=0;i<len;i++){
                    datafullpath=dataServiceInfo.serviceImgs[i].FULLPATH;
                    pathLen=datafullpath.length;
                    lastIndex=datafullpath.lastIndexOf(".");
                    str1=datafullpath.substr(0,lastIndex);
                    str2=datafullpath.substr(lastIndex,pathLen);
                    fullpath=str1+"_max"+str2;
                    imgsData+='<div class="pic-show-l"><img class="person-img" src="'+fullpath +'" alt=""></div>';
                }
                $(".pic-show").html(imgsData);
            }else{
                
            }
        }else{
            console.log("获取数据为空");
        }     
       //判断页面是否收藏
       $(".zwlClo").on("click",function(){
            if(userId>0){
                console.log(flag_collect+"0是收藏1是未收藏");
                if(flag_collect==1){//1是收藏  那么就要取消收藏
                      requestData6=JSON.stringify(
                        {
                            "code":"cancelCollect",
                            "version":"1.0",
                            "data":{
                                "productIds":[productId],
                                "userId":userId
                            }
                        });
                    getData(url,requestData6,call_func_succ2,call_func_err,async,type); 
                }else{
                     requestData1=JSON.stringify(
                        {
                            "code":"serviceCollect",
                            "version":"1.0",
                            "data":{
                                "productId":productId,
                                "userId":userId
                            }
                        });
                            getData(url,requestData1,call_func_succ3,call_func_err,async,type); 
                }
            }else{
                $(".zwl-zwl").fadeIn();
                $(".zwl-zwl").fadeOut();
                
            }
       });
       
       console.log(userId+"userId")
       //用户是否登录
         if(userId>0){
                if(isCollect==0){                          
                   $(".zwlClo_img").attr("src","./images/collect02.png");
                flag_collect=0;

              }else{
                   $(".zwlClo_img").attr("src","./images/collect01.png");
                   
                 flag_collect=1;
              }
         }else{
             $(".zwlClo_img").attr("src","./images/collect02.png");
         }

       function call_func_succ2(data){
            console.log(data);
            if(data.statu==0){
                $(".zwlClo_img").attr("src","./images/collect02.png");
                flag_collect=0;
            }
        }
        function call_func_succ3(data){
            console.log(data);
            if(data.msg=="收藏成功"){
               $(".zwlClo_img").attr("src","./images/collect01.png");
                flag_collect=1;

            }else{
                   $(".zwlClo_img").attr("src","./images/collect02.png");
                flag_collect=0;
            }
        }       
    } 
    function call_func_err(msg){
        console.log(msg);
        console.log("获取数据失败");
    }
});
